<?php
/**
* This file belongs to the core webappkit package (kit)
* @link http://webappkit.net
* @package webappkit
* @author J.Ducastel <jeremie@ducastel.name>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/

/**
* root class for webappkit services.
* services are named object instances providing kit-level functionalities.
* They must be declared within the kit meta-data file, and have their own config file whithin their kit, which will be retrived when built.
* @link http://code.google.com/p/webappkit/wiki/Services
*/
class wakService {
/*--------------------------------------------------------------------
CONSTRUCTOR
--------------------------------------------------------------------*/
	/**
	* php4 constructor
	* @access public
	*/
	function wakService(&$kit,$name) {
		$this->__construct($kit,$name);
	}/**/
	
	/**
	* "real" constructor.
	* will load conf
	* @access public
	* @param webappkit $kit parent kit's reference
	* @param string $name storage name within kit
	*/
	function __construct(&$kit,$name) {
		$this->kit=&$kit;
		$this->name=$name;
		// loading config
		$this->_loadIni();
		// doing some more initialization
		$this->_init();
	}/**/
/*--------------------------------------------------------------------
PUBLIC INSTANCE METHODS
--------------------------------------------------------------------*/
	/**
	* 
	* @param
	* @access public
	* @return 
	* /
	function () {
		
	}/**/
/*--------------------------------------------------------------------
VARS / MEMBERS
--------------------------------------------------------------------*/
	/**
	* @var webappkit parent kit reference
	*/
	var $kit;
	
	/**
	* @var string self unique name within kit
	*/
	var $name;
	
	/**
	* @var array configuration data
	*/
	var $cfg;
	
	/**
	* @var type desc
	*/
	//var //
	
/*--------------------------------------------------------------------
PRIVATE / PROTECTED METHODS
--------------------------------------------------------------------*/
	/**
	* loads config ini file ( {name}.service.ini )
	* @access protected
	* @return bool
	*/
	function _loadIni() {
		// getting ini file
		$file=$this->kit->getPath().$this->name.'.service.ini'; //echo $file;
		if (!file_exists($file) or !is_file($file)) {
			trigger_error("no config file for service ($file)");
			return false;
		}
		// parsing, with sections
		if (!$cfg=parse_ini_file($file,true)) {
			trigger_error("failed to parse $file");
			return false;
		}
		// copying new config
		$this->cfg=array_merge($this->cfg,$cfg);
		// echo '<pre>'; print_r($this->cfg);
		return true;
	}/**/
	
	/**
	* service intialization
	* @access protected
	* @return bool
	*/
	function _init() {
		//echo "building service !";
		return true;
	}/**/
}
?>